<template>
	<view>
		<view class="search">
			<u-search @change="search" @search="search" @custom="search" :animation="true" placeholder="搜索工程师" v-model="keyword"></u-search>
		</view>
		<u-radio-group v-model="engineer" @change="engineerGroupChange">
			<view class="engineer-item" v-for="(item, index) in engineers" :key="index">
				<u-radio :name="item.id">{{item.title}}</u-radio>
			</view>
		</u-radio-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				info: {},
				formButtonStatus: false,
				formButtonStyle: {
					backgroundImage: "linear-gradient(to bottom right, #34E4E8, #1FAEE8)",
					border: 'none',
					color: '#ffffff',
					outline: 'none',
					margin: '60rpx 80rpx 60rpx 80rpx'
				},
				keyword: '',
				engineers: [],
				engineer: 0
			}
		},
		onLoad(query) {
			this.id = query.id ? query.id:0
			this.load()
		},
		methods: {
			engineerGroupChange: function (id) {
				var that = this
				that.$u.api.transferPost({
					id: that.id,
					transfer_engineer: id
				}).then(res => {
					that.$u.toast(res.msg)
					if(res.code == 1) {
						setTimeout(() => {
							uni.navigateBack({
								delta: 2
							})
						}, 2000)
					}
				})
			},
			load: function () {
				var that = this
				that.$u.api.transfer({
					id: this.id
				}).then(res => {
					if (res.code == 0) {
						uni.showModal({
							title: '温馨提示',
							content: res.msg,
							showCancel: false,
							success: res => {
								if (res.confirm) {
									uni.navigateBack({
										delta: 1
									})
								}
							}
						})
					} else {
						that.info = res.data.info
					}
				}).catch(res => {
					that.$u.toast('请求失败，请重试！');
				})
				
				that.search()
			},
			search: function () {
				var that = this
				that.$u.api.searchTransfer({
					keyword: that.keyword
				}).then(res => {
					that.engineers = res.list
				}).catch(res => {
					that.$u.toast('请求失败，请重试！');
				})
			}
		}
	}
</script>

<style>
.search {
	padding: 20rpx;
}
.engineer-item {
	padding: 0 30rpx;
	height: 80rpx;
	display: flex;
	align-items: center;
}
</style>
